﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.Building
{
    public class BuildingListQuery : BasePageQuery
    {
        public string SearchContent { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string ProvinceCode { get; set; } = string.Empty;
        public string CityCode { get; set; } = string.Empty;
        public string CountryCode { get; set; } = string.Empty;
        public string IsDelete { get; set; } = string.Empty;


        public override string Columns()
        {
            return string.Format(" t.building_id as `BuildingId`,t.building_name as `BuildingName`," +
                " t.average_price as `AveragePrice`,t.province_code as `ProvinceCode`,t.province_name as `ProvinceName`," +
                " t.city_code as `CityCode`,t.city_name as `CityName`,t.country_code as `CountryCode`," +
                " t.country_name as `CountryName`,t.status as `Status`,t.is_delete as `IsDelete`,t.ts as `Ts`," +
                " t.created_time as `CreatedTime` ");
        }


        public override (string, List<SugarParameter>) QueryParams()
        {
            List<SugarParameter> parameters = new List<SugarParameter>();
            StringBuilder strWhere = new StringBuilder(" ");

            if (!string.IsNullOrWhiteSpace(SearchContent))
            {
                strWhere.AppendLine(" and ( " +
                    " t.building_name like @searchContent " +
                     ") ");
                parameters.Add(new SugarParameter("searchContent", "%" + SearchContent + "%"));
            }
            if (!string.IsNullOrWhiteSpace(Status))
            {
                strWhere.AppendLine(" and t.status=@status ");
                parameters.Add(new SugarParameter("status", Status));
            }
            if (!string.IsNullOrWhiteSpace(IsDelete))
            {
                strWhere.AppendLine(" and t.is_delete=@isDelete ");
                parameters.Add(new SugarParameter("isDelete", IsDelete));
            }
            if (!string.IsNullOrWhiteSpace(ProvinceCode)) {
                strWhere.AppendLine(" and t.province_code=@provinceCode ");
                parameters.Add(new SugarParameter("provinceCode", ProvinceCode));
            }
            if (!string.IsNullOrWhiteSpace(CityCode))
            {
                strWhere.AppendLine(" and t.city_code=@cityCode ");
                parameters.Add(new SugarParameter("cityCode", CityCode));
            }
            if (!string.IsNullOrWhiteSpace(CountryCode))
            {
                strWhere.AppendLine(" and t.country_code=@countryCode ");
                parameters.Add(new SugarParameter("countryCode", CountryCode));
            }

            return (strWhere.ToString(), parameters);
        }

        public override string Tables()
        {
            return " `building` t ";
        }
    }
}
